<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>商家申请</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	    <link rel="stylesheet" href="__PUBLIC__/static/wx/css/iconfont.css" />
	    <link rel="stylesheet" href="__PUBLIC__/static/wx/css/new.css" />
	    <link rel="stylesheet" href="__PUBLIC__/static/wx/css/style.css" />
		<style type="text/css">
			body{background: #f4f4f4;}
			* {
			    -webkit-user-select: text;
			    -user-select: text;
			}
		.sjsq_list input {
		    -webkit-user- select: auto!important;
		    -khtml-user-select: auto!important;
		    -moz-user-select: auto!important;
		    -ms-user-select: auto!important;
		    -o-user-select: auto!important;
		    user-select: auto!important;
		}
		</style>
	</head>
	<body>
		<header class="header">
			<a class="left" href="JavaScript:history.go(-1)"> < </a>
			<h1 class="mui-title">商家申请</h1>
		</header> 
		<div class="mui-content" style="padding: 44px 0 0;">
			{if $qy.state==2}
			<p class="bt" style="text-align: center;color: red;font-size: 18px;">申请审核中，请等待客服联系</p>
			{elseif $qy.state==3}
			<p class="bt" style="text-align: center;color: red;font-size: 18px;">申请被驳回，请重新提交</p>
			{/if}
			<form class="layui-form update_form"  id="my_form" method="POST"> 
			<input type="hidden" name="id" value="{$qy.id}" />
			{if condition="($qy.state eq 0) OR ($qy.state eq 3)"}
			   <div class="sjsq_tips">为了尽快通过审核，请确认以下信息准确无误。</div>
			{/if}
			<ul class="sjsq_list">
				<li class="clearfix">
					<span class="left">店铺名称</span>
					<span class="right"><input type="text" id="agent_name1" name="agent_name1" value="{$qy.agent_name1}" placeholder="请填写店铺名称"></span>
				</li>
				<li class="clearfix">
					<span class="left">联系人</span>
					<span class="right"><input type="text" id="contacts" name="contacts" value="{$qy.contacts}" placeholder="请输入联系人姓名"></span>
				</li>
				<!--已绑定手机号-->
				{empty name="mobile"}
				<li class="clearfix yzm">	
					<p style="font-size: 6px;color: red;">注意：以下填写的手机号同步绑定为会员手机号</p>
					<span class="right"><input type="tel" id="mobile" name="contact_tel" placeholder="请填写您的手机号码"></span>
					<span class="left"  id="send_code"><a href="#">获取验证码</a></span>
				</li>
				<li class="clearfix yzm"><input type="text" id="yzm" name="yzm" placeholder="请填写您的手机短信验证码"></li>
				{else /}
				<!--未绑定手机号-->
				<li class="clearfix">
					<span class="left">手机号</span>
					<span class="right"><input type="tel" id="mobile" name="contact_tel" value="{$qy.state ==1 || $qy.state ==2 ?$qy.contact_tel:$mobile}" placeholder="请填写您的手机号码"></span>
				</li>
			    {/empty}
			</ul> 
			{if condition="($qy.state eq 0) OR ($qy.state eq 3)"}
			<button type="button" class="sjsq_btn">提交申请</button>		
			{/if}
			</form>
			{if $qy.state!=1}
			<p class="sjsq_tips2">1-3个工作日完成，后台客服人员将会联系您，请保持电话畅通。</p>
			{/if}
		</div>
	</body>
</html>

{include file="public/footer" /}
<script>
	var onoff = true;
	//获取验证码
	$('#send_code').click(function() {
		//false就不能发送
		if(!onoff) {
			return;
		}
		onoff = false;
		//点击玩按钮干什么?
		//发验证码? 
		// 1-给谁发? 手机号码
		var phone = $("#mobile").val(); 
		if(phone == '') {
			layer.msg('手机号码不能为空');
			onoff = true;
			return;
		}
		var reg = /^1[3|4|5|6|7|8|9][0-9]{9}$/; //验证规则
		if(!reg.test(phone)) {
			layer.msg('手机号码格式不正确');
			onoff = true;
			return;
		}
		$.ajax({
			type:"post",
			//请求的url
			//注意，如果我们使用路由器的情况下，我们需要设置一下本地服务器的ip地址
			url: "{:url('index/index/verify_code')}",
			//请求的过程中传递过去的参数 json
			data: {
				mobile: phone,
			},
			//成功了的回调，并且带有返回值
			success: function(data) {
				layer.msg(data.msg);
				var num = 60;
				var timer = setInterval(function() {
					num--;
					if(num == 0) {
						$('#send_code').text('发送验证码');
						//定时器停了
						clearInterval(timer);
						onoff = true;
					} else {
						$('#send_code').text(num + 'S');
					}
				}, 1000); // 1000 毫秒==1秒
			}
		})
	});
</script>

<script>  
	$(".sjsq_btn").click(function(){   
		if($("input[name='agent_name1']").val() == ''){
			layer.msg("请输入商户名称");
			return false;
		}
		if($("input[name='contacts']").val() == ''){
			layer.msg("请输入联系人姓名");
			return false;
		}
		if($("input[name='mobile']").val() == ''){
			layer.msg("请填写您的手机号码");
			return false;
		}
		if($("input[name='yzm']").val() == ''){
			layer.msg("请填写您的验证码");
			return false;
		}
		
		$.ajax({
				type: 'post',
				url: 'agentsq',
				data: $('#my_form').serialize(),
				success: function(data) {				
					if(data.code == 200) {
						layer.msg(data.msg, {
							icon: 1,
							time: 1500 //2秒关闭（如果不配置，默认是3秒）
						}, function() {
							window.location.reload();
							location.href = "{:url('agentsq')}";
						});
					} else {
						layer.msg(data.msg); //保存成功提示
					}
				},
				error: function(data) {
					var a = data;
				}			

			})
	

	})
</script>
